class node():
    def __init__(self,x=-1):
        self.data=x
        self.prev=None
        self.next=None

class linked_list():
    def __init__(self):
        self.head=None
    def insert(self,x):
        if self.head==None:
            self.head=node(x)
        else:
            a=node(x)
            a.next=self.head
            self.head.prev=a
            self.head=a
    def search(self,k):
        current=self.head
        while current!=None and current.data!=k:
            current=current.next
        return current
    def delete(self,n):#n是要删除的节点
        if n.prev!=None:
            n.prev.next=n.next
        else:
            self.head=n.next
        if n.next!=None:
            n.next.prev=n.prev
        
    def lookatme(self):
        current=self.head
        while current!=None:
            print current.data, 
            current=current.next
        print

if __name__=='__main__':
    a=linked_list()
    for i in range(10):
        a.insert(i+1)
    a.lookatme()
    a.delete(a.search(5))
    a.lookatme()
        
